<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Jbuss</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">

</head>

<body class="top-navigation">

    <div id="wrapper" style="height:100%;">
        <div id="page-wrapper" class="gray-bg" style="height:100%;">
        <div class="row border-bottom white-bg">
        <nav class="navbar navbar-expand-lg navbar-static-top" role="navigation">
            <div class="navbar-collapse collapse" id="navbar">
                <ul class="nav navbar-nav mr-auto" id="side-menu">
                </ul>
                <ul class="nav navbar-top-links navbar-right">
                    <li>
                        <a href="javascript:logout();">
                            <i class="fa fa-sign-out"></i> Log out
                        </a>
                    </li>
                </ul>
            </div>
        </nav>
        </div>
        <div class="J_mainContent"  id="content-main" style="height: calc(100% - 100px);">
	    <iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="first.html" frameborder="0" data-id="first.html" seamless></iframe>
        </div>
        <div class="footer" style="position: absolute;width: 100%;bottom: 0;">
	    <div class="pull-left" style="color:red;font-size:12px;">
            </div>
            <div class="pull-right">&copy; 2020 <a href="https://www.sudo.ren" target="_blank">为道日损</a>
            </div>
        </div>
    </div>
</div>



    <!-- Mainly scripts -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="js/plugins/pace/pace.min.js"></script>
    <script src="js/plugins/layui/layer/layer.js"></script>
    <script src="js/plugins/toastr/toastr.min.js"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script>
	
		$(function(){
			if(!getMySimpleInfo()){return;}
			
			var url = 'sysMenu/queryMySysMenu';
			jQuery.ajax({
				url:domain + url,
				type:"get",
				data:{},
				crossDomain:true,
				async:false,
				xhrFields:{
					withCredentials:true
				},
				success:function (data) {
					if(data.status == 200){
						combHTML(data.data);
					}else{
						top.toastr.error(data.msg);
					}
				},
				error:function(data) {
					top.toastr.error("菜单加载失败，请检查网络");
				}
			})

			document.addEventListener("error", function (e) {
    				var elem = e.target;
    				if (elem.tagName.toLowerCase() === 'img') {
        				var notFoundImgSrt = $(elem).attr("notFoundSrc");
       					 if (notFoundImgSrt) {
           				 $.get(notFoundImgSrt, null, function (response, status, xhr) {
               				 if (xhr.status === 200)
                    				elem.src = notFoundImgSrt;
           				 });
        				}
    				}
			}, true);
		})
		
		function getMySimpleInfo(){
			var url = '/sysUser/getMySimpleUserInfo';
			var bool = true;
			jQuery.ajax({
				url:domain + url,
				type:"get",
				crossDomain:true,
				async:false,
				xhrFields:{
					withCredentials:true
				},
				success:function (data) {
					if(data.status == 200){
						combMyInfoHTML(data.data);
					}else{
						bool = false;
						top.toastr.error(data.msg);
						setInterval(function(){
							window.location.href = "login.html";
						},3000);
						return;
					}
				},
				error:function(data) {
					bool = false;
					top.toastr.error("查询失败，请检查网络");
				}
			})
			return bool;
		}
	
		function logout(){
			//layui.use(['layer'], function(){
				//var layer = layui.layer;
				layer.confirm('确定退出？', {
					title:false,
					icon:7,
					btn: ["确定",'取消'] //按钮
				}, function(){
					var url = 'sysUser/logout';
					jQuery.ajax({
						url:domain + url,
						type:"post",
						crossDomain:true,
						xhrFields:{
							withCredentials:true
						},
						success:function (data) {
							window.location.href = "login.html";
						},
						error:function(data) {
							top.toastr.error("退出失败，请检查网络");
						}
					})
				})
			//})
		}
		
		function combHTML(data){
			var htmls = new Array();
			for(var i = 0;i<data.length;i++){
				if(data[i].pCode == "0000"){
					var c1 = data[i].mCode;
					var c1name = data[i].mName;
					var c1icon = data[i].mIcon;
					htmls.push('<li class="dropdown"><a aria-expanded="false" role="button" href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa '+ c1icon +'"></i>'+ c1name +'</a>');
					htmls.push('		<ul role="menu" class="dropdown-menu">');
					
					for(var j = 0;j<data.length;j++){
						if(data[j].pCode == c1){
							var c2 = data[j].mCode;
							var c2name = data[j].mName;
							var c2icon = data[j].mIcon;
							var c2murl = data[j].mUrl;
							var c2note = data[j].note;
							htmls.push('	<li><a class="J_menuItem" data-note="'+ c2note +'" onclick="showNote(this)" href="'+ c2murl +'">'+ c2name +'</a>');
							
							if(!!c2murl) {
								htmls.push('</li>');
								continue;
							}
							htmls.push('		<ul class="nav nav-third-level">');
							
							for(var k = 0;k<data.length;k++){
								if(data[k].pCode == c2){
									var c3 = data[k].mCode;
									var c3name = data[k].mName;
									var c3icon = data[k].mIcon;
									var c3murl = data[k].mUrl;
									var c3note = data[k].note;
									
									htmls.push('<li><a class="J_menuItem" data-note="'+ c3note +'" onclick="showNote(this)" href="'+ c3murl +'">' + c3name + '</a></li>');
								}
							}
							htmls.push('		</ul>');
							htmls.push('	</li>');
						}
					
					}
					htmls.push('		</ul>');
					htmls.push('</li>');
				}
				
			}
			$("#side-menu").html(htmls.join(''));
			//htmls.push('<script type="text/javascript" src="js/plugins/metisMenu/jquery.metisMenu.js"><\/script>');//ifram切换
			//htmls.push('<script src="js/hplus.min.js?v=4.0.0"><\/script>');
			
			setTimeout(loadScript,0);
		}
		
		function showNote(obj){
			$(".footer .pull-left").html($(obj).data("note"));
		}
		
		function loadScript(){
			var script = document.createElement("script");
			script.src="js/contabs.min.js";	//左侧导航菜单折叠
			document.body.appendChild(script);
			
			//var script1 = document.createElement("script");
			//script1.src="js/plugins/metisMenu/jquery.metisMenu.js";	//ifram切换
			//document.body.appendChild(script1);
			
			var script2 = document.createElement("script");
			script2.src="js/hplus.min.js?v=4.0.0";	
			document.body.appendChild(script2);
			
			
		}
		
		function combMyInfoHTML(data){
			$("#myUR").find(".font-bold").html(data.nickName);
			$("#myUR").find(".text-muted").html(data.roleName);
			$("#myUR").find(".img-circle").attr("src",domain+data.profilePhoto+"?t="+Math.random());
			
		}
		
	</script>
</body>

</html>
